Skip to content

chore(dashboards): Discover split for self hosted dashboard discover widgets #92135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 26, 2025

Conversation

nikkikapadia
Copy link
Member

The discover split for dashboards has been done for all users except self-hosted users. This migration converts all Discover widget types to either Transaction or Error using the _get_and_save_split_decision_for_dashboard_widget function. This function will try to appropriately categorize a widget query as Transaction or Error and will default to Error if a decision cannot be made. This uses the same logic of the original discover split job.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label May 22, 2025
Copy link

codecov bot commented May 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #92135      +/-   ##
==========================================
- Coverage   87.93%   87.90%   -0.04%     
==========================================
  Files       10174    10193      +19     
  Lines      583385   583854     +469     
  Branches    22596    22606      +10     
==========================================
+ Hits       512992   513218     +226     
- Misses      69941    70184     +243     
  Partials      452      452              

Copy link
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/0912_split_discover_dataset_dashboards_self_hosted.py

for 0912_split_discover_dataset_dashboards_self_hosted in sentry

--
-- Raw Python operation
--
-- THIS OPERATION CANNOT BE WRITTEN AS SQL

) -> None:
DashboardWidgetQuery = apps.get_model("sentry", "DashboardWidgetQuery")
catch_all_unsplit_widgets = Q(
widget__widget_type=DashboardWidgetTypes.DISCOVER,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's copy over all the enums into the migration file- it's a good practice to not reference application code in the migration. In case someone changes the enums in the application code, we know it's not going to break the migration if it's copied over here

Comment on lines 46 to 49
queryset = DashboardWidgetQuery.objects.filter(
widget__widget_type=DashboardWidgetTypes.ERROR_EVENTS,
widget__dataset_source=DatasetSourcesTypes.UNKNOWN.value,
).select_related("widget__dashboard__organization")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need the select related here. Also, this revert is missing transaction widgets:

    queryset = DashboardWidgetQuery.objects.filter(
        widget__discover_widget_split__in=[DashboardWidgetTypes.ERROR_EVENTS, DashboardWidgetTypes.TRANSACTION_LIKE],
    )

try:
_get_and_save_split_decision_for_dashboard_widget(widget_query, dry_run=False)
except Exception:
widget_query.widget.widget_type = DashboardWidgetTypes.ERROR_EVENTS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_get_and_save_split_decision_for_dashboard_widget only updates discover_widget_split and dataset_source, so that's what we should do here also. Let's not update widget_type here.

Copy link
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/0913_split_discover_dataset_dashboards_self_hosted.py

for 0913_split_discover_dataset_dashboards_self_hosted in sentry

--
-- Raw Python operation
--
-- THIS OPERATION CANNOT BE WRITTEN AS SQL

@nikkikapadia nikkikapadia marked this pull request as ready for review May 26, 2025 13:55
@nikkikapadia nikkikapadia requested a review from a team as a code owner May 26, 2025 13:55
"""
TRANSACTION_LIKE = 101
"""
This targets transaction-like data from the split from discover. Itt may either use 'Transactions' events or 'PerformanceMetrics' depending on on-demand, MEP metrics, etc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This targets transaction-like data from the split from discover. Itt may either use 'Transactions' events or 'PerformanceMetrics' depending on on-demand, MEP metrics, etc.
This targets transaction-like data from the split from discover. It may either use 'Transactions' events or 'PerformanceMetrics' depending on on-demand, MEP metrics, etc.

"""
SPANS = 102
"""
These represent the logs trace item type on the EAP dataset.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be for logs or spans?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description is supposed to be for logs. I'll move it to after the logs definition for consistency 👍

from django.db.migrations.state import StateApps
from django.db.models import Q

from sentry.discover.dashboard_widget_split import _get_and_save_split_decision_for_dashboard_widget
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally don't import from application code into migrations, as import errors can creep in. I remember this came up in a previous discover dataset split discussion, and there was enough logic in this that cloning it into the migrations wasn't simple. I'm assuming that is still the case, and that we're going to be careful with this function for as long as this migration lives (which could be years).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup same case, we'll be keeping an eye on this function

Copy link
Member

@markstory markstory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@nikkikapadia nikkikapadia merged commit a2ea48a into master May 26, 2025
61 checks passed
@nikkikapadia nikkikapadia deleted the nikki/discover-split-self-hosted branch May 26, 2025 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants